package com.xrui.kafka.mgrutil

import java.time.Duration
import java.util.Properties

import com.xrui.avro.AvroUtil
import com.xrui.kafka.core.factory.{KafkaFactory, KafkaService}
import com.xrui.kafka.message.AvroMessage
import com.xrui.kafka.message.AvroMessage.MsgOperation
import org.apache.avro.Schema
import org.apache.kafka.clients.CommonClientConfigs
import org.apache.kafka.clients.admin.AdminClient
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.common.TopicPartition
import org.apache.log4j.PropertyConfigurator
import org.slf4j.{Logger, LoggerFactory}

import scala.collection.JavaConverters._
import scala.collection.mutable

class KafkaUtilV2 {

    def getConsumerLag2(consumerGroupId:String )  = {

        val (beginOffsets, endOffsets) = getTopicOffset(KafkaUtilV2.topics,"",KafkaUtilV2.brokers)

        val topicPartition2Lag = mutable.HashMap.empty[TopicPartition,(Long,Long,Long)]
        val adminClient        = KafkaUtilV2.getAdminClient()
        val offsets            = adminClient.listConsumerGroupOffsets(consumerGroupId)
        val offsetsMeta        = offsets.partitionsToOffsetAndMetadata.get()

        if(offsetsMeta.isEmpty){
            endOffsets.forEach((partition, offset) =>
            {
                val consumerOffset = KafkaUtilV2.kafkaService.getOffset("beta",
                    partition.topic(),
                    consumerGroupId,
                    partition.partition()
                )

                //System.out.println( s"consumter: ${consumerGroupId}, topic:${partition.topic()}, partition: ${partition.partition()} , lag: ${offset - consumerOffset.getOffset()}" )

                val beginOffset = beginOffsets.get(partition)
                topicPartition2Lag.put(partition, (beginOffset,offset , consumerOffset.getOffset()))

            }
            )
        }
        else{
            offsetsMeta.forEach((partition,offsetMetadata) =>
            {

                val topicEndOffset = endOffsets.get(partition)
                //System.out.println( s"consumter: ${consumerGroupId}, topic:${partition.topic()}, partition: ${partition.partition()} , lag: ${topicEndOffset - offsetMetadata.offset()}" )
                val beginOffset = beginOffsets.get(partition)
                topicPartition2Lag.put(partition, (beginOffset, topicEndOffset , offsetMetadata.offset()))
            }
            )

        }
        topicPartition2Lag
    }

    def getTopicOffset( topics:String,consumerGroupId:String,brokers:String)  = {
        val consumerProps = new Properties()
        if(consumerGroupId.isEmpty()){
            consumerProps.put("group.id", "kafkaMonitor")
        }
        else {
            consumerProps.put("group.id", consumerGroupId)
        }

        consumerProps.put("bootstrap.servers", brokers)
        consumerProps.put("enable.auto.commit", "false")
        consumerProps.put("fetch.message.max.bytes", (1024 * 1024 * 200).toString)
        consumerProps.put("auto.offset.reset", "earliest")
        consumerProps.put("session.timeout.ms", "30000")
        consumerProps.put("key.deserializer", "org.apache.kafka.common.serialization.ByteArrayDeserializer")
        consumerProps.put("value.deserializer", "org.apache.kafka.common.serialization.ByteArrayDeserializer")

        val consumer = new KafkaConsumer[Array[Byte], Array[Byte]](consumerProps)

        val tpconsumer.subscribe(tps)

        consumer.poll(Duration.ofMillis(10000))

        val assignments = consumer.assignment

        val startOffset = consumer.beginningOffsets(assignments)
        System.out.println("startoffset: ")
        startOffset.forEach((key, value) => {
            System.out.println(s"    $key :  $value")
        }
        )


        val endOffset = consumer.endOffsets(assignments)
        System.out.println(s"endoffset: ")
        endOffset.forEach((key, value) => {
            System.out.println(s"    $key :  $value")
        }
        )
        consumer.close()
        (startOffset,endOffset)

    }

    def getBrokers():Unit ={
        val brokers = KafkaUtilV2.kafkaService.getAllBrokersInfo("beta")
        KafkaUtilV2.kafkaService.getKafkaLogSize("beta","ecpcisqeddscat.data.v2.index.CL3Instrument_search",0)
        return
    }

    def getConsumerLag(  consumerGroupId:String ):Unit = {
        val tps = KafkaUtilV2.topics.split(",")
        tps.toStream.foreach(e => {
            val ret = KafkaUtilV2.kafkaService.getLag("beta",consumerGroupId,e)
              System.out.println(s"Topic: ${e}, consumer: ${consumerGroupId}, lag: ${ret} ")
        })

    }

    def describeTopics()  ={

        val adminClient = KafkaUtilV2.getAdminClient()

        val tps = KafkaUtilV2.topics.split(",")
        val javaTopics = new java.util.ArrayList[String]
        tps.map(e=> javaTopics.add(e))

        val cluster   = adminClient.describeCluster()
        val clusterId = cluster.clusterId().get()
        val nodes     = cluster.nodes().get()

        val tpr       = adminClient.listTopics()
        val tpnames   = tpr.names().get()

        val descTP    = adminClient.describeTopics(javaTopics)


        val allInfo = descTP.all

        try {
            val all = allInfo.get
            all.forEach((topic,description) => {
                System.out.println(s"${description.toString}")
            })
        } catch {
            case e: Exception =>
                System.out.println("查询topic信息失败！：" + e.getMessage)
        }


    }

  val schemastr = """{"type":"record","name":"schema","namespace":"auto.generated","fields":[{"name":"DealFacilityId","type":["null","long"]},{"name":"LpcTrancheId","type":["null","string"]},{"name":"AdditionalFeesTexts","type":["null",{"type":"record","name":"AdditionalFeesTexts","fields":[{"name":"AddlFeesText","type":["null",{"type":"record","name":"AddlFeesText","namespace":"auto.generated.AdditionalFeesTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.AdditionalFeesTexts.AddlFeesText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"AllFees","type":["null",{"type":"record","name":"AllFees","fields":[{"name":"AllFeeCode","type":["null",{"type":"array","items":{"type":"record","name":"AllFeeCode","namespace":"auto.generated.AllFees","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}}]}]}]},{"name":"AllMargins","type":["null",{"type":"record","name":"AllMargins","fields":[{"name":"AllMargin","type":["null",{"type":"array","items":{"type":"record","name":"AllMargin","namespace":"auto.generated.AllMargins","fields":[{"name":"AppMarginsLevel","type":["null",{"type":"record","name":"AppMarginsLevel","namespace":"auto.generated.AllMargins.AllMargin","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"AppMarginsText","type":["null",{"type":"record","name":"AppMarginsText","namespace":"auto.generated.AllMargins.AllMargin","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.AllMargins.AllMargin.AppMarginsText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}}]}]}]},{"name":"AlternateBaseRateDescriptionTexts","type":["null",{"type":"record","name":"AlternateBaseRateDescriptionTexts","fields":[{"name":"AbrText","type":["null",{"type":"record","name":"AbrText","namespace":"auto.generated.AlternateBaseRateDescriptionTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.AlternateBaseRateDescriptionTexts.AbrText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"AlternateBaseRates","type":["null",{"type":"record","name":"AlternateBaseRates","fields":[{"name":"AlternateBaseRate","type":["null",{"type":"array","items":{"type":"record","name":"AlternateBaseRate","namespace":"auto.generated.AlternateBaseRates","fields":[{"name":"AbrCode","type":["null",{"type":"record","name":"AbrCode","namespace":"auto.generated.AlternateBaseRates.AlternateBaseRate","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"AbrSpread","type":["null",{"type":"record","name":"AbrSpread","namespace":"auto.generated.AlternateBaseRates.AlternateBaseRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]}]}}]}]}]},{"name":"AnnounceDate","type":["null",{"type":"record","name":"AnnounceDate","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"BorrowerCidgen","type":["null",{"type":"record","name":"BorrowerCidgen","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"BorrowerCountryOfRiskCode","type":["null",{"type":"record","name":"BorrowerCountryOfRiskCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"BorrowerCountryOfRiskId","type":["null",{"type":"record","name":"BorrowerCountryOfRiskId","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.BorrowerCountryOfRiskId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"BorrowerEntityId","type":["null",{"type":"record","name":"BorrowerEntityId","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.BorrowerEntityId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"CallDate","type":["null",{"type":"record","name":"CallDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"CallDescriptionTexts","type":["null",{"type":"record","name":"CallDescriptionTexts","fields":[{"name":"CallText","type":["null",{"type":"record","name":"CallText","namespace":"auto.generated.CallDescriptionTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.CallDescriptionTexts.CallText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"CallFreqCode","type":["null",{"type":"record","name":"CallFreqCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"CallTypeCode","type":["null",{"type":"record","name":"CallTypeCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"ConvDate","type":["null",{"type":"record","name":"ConvDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"ConvTypeSecCode","type":["null",{"type":"record","name":"ConvTypeSecCode","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"ConversionDescriptionTexts","type":["null",{"type":"record","name":"ConversionDescriptionTexts","fields":[{"name":"ConversionText","type":["null",{"type":"record","name":"ConversionText","namespace":"auto.generated.ConversionDescriptionTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.ConversionDescriptionTexts.ConversionText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"CouponRatePct","type":["null",{"type":"record","name":"CouponRatePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"CreditEnhancements","type":["null",{"type":"record","name":"CreditEnhancements","fields":[{"name":"CreditEnhanceCode","type":["null",{"type":"array","items":{"type":"record","name":"CreditEnhanceCode","namespace":"auto.generated.CreditEnhancements","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}}]}]}]},{"name":"DateOfLatestIsuProcess","type":["null",{"type":"record","name":"DateOfLatestIsuProcess","fields":[{"name":"v","type":["null","long"],"doc":"datetime"}]}]},{"name":"DateTrancheWasCreated","type":["null",{"type":"record","name":"DateTrancheWasCreated","fields":[{"name":"v","type":["null","long"],"doc":"datetime"}]}]},{"name":"DateTrancheWasLastUpdated","type":["null",{"type":"record","name":"DateTrancheWasLastUpdated","fields":[{"name":"v","type":["null","long"],"doc":"datetime"}]}]},{"name":"DcnNumber","type":["null",{"type":"record","name":"DcnNumber","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"DealTrancheId","type":["null",{"type":"record","name":"DealTrancheId","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.DealTrancheId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"DebtToCFMax","type":["null",{"type":"record","name":"DebtToCFMax","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"DebtToCFMin","type":["null",{"type":"record","name":"DebtToCFMin","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"DebtToCapitalMax","type":["null",{"type":"record","name":"DebtToCapitalMax","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"DebtToCapitalMin","type":["null",{"type":"record","name":"DebtToCapitalMin","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"DebtToNWMax","type":["null",{"type":"record","name":"DebtToNWMax","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"DebtToNWMin","type":["null",{"type":"record","name":"DebtToNWMin","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"DrawdownEndDate","type":["null",{"type":"record","name":"DrawdownEndDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"DrawdownFeaturesTexts","type":["null",{"type":"record","name":"DrawdownFeaturesTexts","fields":[{"name":"DrawdownText","type":["null",{"type":"record","name":"DrawdownText","namespace":"auto.generated.DrawdownFeaturesTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.DrawdownFeaturesTexts.DrawdownText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"DrawdownOptionalCurrencies","type":["null",{"type":"record","name":"DrawdownOptionalCurrencies","fields":[{"name":"DrawdownOptionalCurrency","type":["null",{"type":"array","items":{"type":"record","name":"DrawdownOptionalCurrency","namespace":"auto.generated.DrawdownOptionalCurrencies","fields":[{"name":"OptionalCurrencyCode","type":["null",{"type":"record","name":"OptionalCurrencyCode","namespace":"auto.generated.DrawdownOptionalCurrencies.DrawdownOptionalCurrency","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"OptionalCurrencyId","type":["null",{"type":"record","name":"OptionalCurrencyId","namespace":"auto.generated.DrawdownOptionalCurrencies.DrawdownOptionalCurrency","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.DrawdownOptionalCurrencies.DrawdownOptionalCurrency.OptionalCurrencyId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]}]}}]}]}]},{"name":"DrawdownStartDate","type":["null",{"type":"record","name":"DrawdownStartDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"DrawnPricings","type":["null",{"type":"record","name":"DrawnPricings","fields":[{"name":"DrawnPricing","type":["null",{"type":"array","items":{"type":"record","name":"DrawnPricing","namespace":"auto.generated.DrawnPricings","fields":[{"name":"DrawnSpread","type":["null",{"type":"record","name":"DrawnSpread","namespace":"auto.generated.DrawnPricings.DrawnPricing","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"DrawnPricing","type":["null",{"type":"record","name":"DrawnPricing","namespace":"auto.generated.DrawnPricings.DrawnPricing","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"IsDrawnInitial","type":["null",{"type":"record","name":"IsDrawnInitial","namespace":"auto.generated.DrawnPricings.DrawnPricing","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsDrawnFloat","type":["null",{"type":"record","name":"IsDrawnFloat","namespace":"auto.generated.DrawnPricings.DrawnPricing","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"DrawnLevel","type":["null",{"type":"record","name":"DrawnLevel","namespace":"auto.generated.DrawnPricings.DrawnPricing","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]}]}}]}]}]},{"name":"EcrMax","type":["null",{"type":"record","name":"EcrMax","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"EcrMin","type":["null",{"type":"record","name":"EcrMin","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"EnhancementDescriptionTexts","type":["null",{"type":"record","name":"EnhancementDescriptionTexts","fields":[{"name":"EnhancementText","type":["null",{"type":"record","name":"EnhancementText","namespace":"auto.generated.EnhancementDescriptionTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.EnhancementDescriptionTexts.EnhancementText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"EqualRepymtAmtInHostCurr","type":["null",{"type":"record","name":"EqualRepymtAmtInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.EqualRepymtAmtInHostCurr","fields":[{"name":"scale","type":["null","long"],"doc":"long"},{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"FinalMaturityDate","type":["null",{"type":"record","name":"FinalMaturityDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"FitchLoanRatingNumber","type":["null",{"type":"record","name":"FitchLoanRatingNumber","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"GuaranteeDescriptionTexts","type":["null",{"type":"record","name":"GuaranteeDescriptionTexts","fields":[{"name":"GuaranteeText","type":["null",{"type":"record","name":"GuaranteeText","namespace":"auto.generated.GuaranteeDescriptionTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.GuaranteeDescriptionTexts.GuaranteeText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"Guarantors","type":["null",{"type":"record","name":"Guarantors","fields":[{"name":"Guarantor","type":["null",{"type":"array","items":{"type":"record","name":"Guarantor","namespace":"auto.generated.Guarantors","fields":[{"name":"GuarantorEntityId","type":["null",{"type":"record","name":"GuarantorEntityId","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.Guarantors.Guarantor.GuarantorEntityId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"GuarantorImmParentCidgen","type":["null",{"type":"record","name":"GuarantorImmParentCidgen","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"GuarantorUltParentCidgen","type":["null",{"type":"record","name":"GuarantorUltParentCidgen","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"GuarantorUltParentEntityId","type":["null",{"type":"record","name":"GuarantorUltParentEntityId","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.Guarantors.Guarantor.GuarantorUltParentEntityId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"IsPrimParentOrGovtGuarantor","type":["null",{"type":"record","name":"IsPrimParentOrGovtGuarantor","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"GuarantorCidgen","type":["null",{"type":"record","name":"GuarantorCidgen","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"GuarantorImmParentEntityId","type":["null",{"type":"record","name":"GuarantorImmParentEntityId","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.Guarantors.Guarantor.GuarantorImmParentEntityId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"IsPrimGuarantor","type":["null",{"type":"record","name":"IsPrimGuarantor","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"MidParents","type":["null",{"type":"record","name":"MidParents","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"MidParent","type":["null",{"type":"array","items":{"type":"record","name":"MidParent","namespace":"auto.generated.Guarantors.Guarantor.MidParents","fields":[{"name":"GuarantorMidParentEntityId","type":["null",{"type":"record","name":"GuarantorMidParentEntityId","namespace":"auto.generated.Guarantors.Guarantor.MidParents.MidParent","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.Guarantors.Guarantor.MidParents.MidParent.GuarantorMidParentEntityId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"GuarantorMidParentCidgen","type":["null",{"type":"record","name":"GuarantorMidParentCidgen","namespace":"auto.generated.Guarantors.Guarantor.MidParents.MidParent","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]}]}}]}]}]},{"name":"GuarantorTypeCode","type":["null",{"type":"record","name":"GuarantorTypeCode","namespace":"auto.generated.Guarantors.Guarantor","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]}]}}]}]}]},{"name":"HasAbr","type":["null",{"type":"record","name":"HasAbr","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasAddlCompPaidToMgr","type":["null",{"type":"record","name":"HasAddlCompPaidToMgr","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasAvailFeeInfo","type":["null",{"type":"record","name":"HasAvailFeeInfo","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasEqRepymts","type":["null",{"type":"record","name":"HasEqRepymts","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasFixedRateOption","type":["null",{"type":"record","name":"HasFixedRateOption","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasImmCommitmentDrawdown","type":["null",{"type":"record","name":"HasImmCommitmentDrawdown","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasInstLender","type":["null",{"type":"record","name":"HasInstLender","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasLeadBookRunner","type":["null",{"type":"record","name":"HasLeadBookRunner","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasMandLoanConv","type":["null",{"type":"record","name":"HasMandLoanConv","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasMandReduction","type":["null",{"type":"record","name":"HasMandReduction","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasPubDisclosedFeeInfo","type":["null",{"type":"record","name":"HasPubDisclosedFeeInfo","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasRelatedMnaDeal","type":["null",{"type":"record","name":"HasRelatedMnaDeal","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasRevolvingLoan","type":["null",{"type":"record","name":"HasRevolvingLoan","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasSchedRepymt","type":["null",{"type":"record","name":"HasSchedRepymt","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"HasSponsor","type":["null",{"type":"record","name":"HasSponsor","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"InterestPaymentFeaturesTexts","type":["null",{"type":"record","name":"InterestPaymentFeaturesTexts","fields":[{"name":"IntPymtText","type":["null",{"type":"record","name":"IntPymtText","namespace":"auto.generated.InterestPaymentFeaturesTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.InterestPaymentFeaturesTexts.IntPymtText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"InterestPayments","type":["null",{"type":"record","name":"InterestPayments","fields":[{"name":"InterestPayment","type":["null",{"type":"array","items":{"type":"record","name":"InterestPayment","namespace":"auto.generated.InterestPayments","fields":[{"name":"IntPeriodFreqCode","type":["null",{"type":"record","name":"IntPeriodFreqCode","namespace":"auto.generated.InterestPayments.InterestPayment","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"DefaultPaymentTexts","type":["null",{"type":"record","name":"DefaultPaymentTexts","namespace":"auto.generated.InterestPayments.InterestPayment","fields":[{"name":"DefaultPymtText","type":["null",{"type":"array","items":{"type":"record","name":"DefaultPymtText","namespace":"auto.generated.InterestPayments.InterestPayment.DefaultPaymentTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.InterestPayments.InterestPayment.DefaultPaymentTexts.DefaultPymtText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}}]}]}]},{"name":"IntPymtDefaultRate","type":["null",{"type":"record","name":"IntPymtDefaultRate","namespace":"auto.generated.InterestPayments.InterestPayment","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"IntPymtBaseRateCode","type":["null",{"type":"record","name":"IntPymtBaseRateCode","namespace":"auto.generated.InterestPayments.InterestPayment","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"IntPymtSchedText","type":["null",{"type":"record","name":"IntPymtSchedText","namespace":"auto.generated.InterestPayments.InterestPayment","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.InterestPayments.InterestPayment.IntPymtSchedText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"NumOfDaysUsedToComputeInt","type":["null",{"type":"record","name":"NumOfDaysUsedToComputeInt","namespace":"auto.generated.InterestPayments.InterestPayment","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"IntPymtFreqCode","type":["null",{"type":"record","name":"IntPymtFreqCode","namespace":"auto.generated.InterestPayments.InterestPayment","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]}]}}]}]}]},{"name":"IsActiveDeal","type":["null",{"type":"record","name":"IsActiveDeal","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsCallOrPutUnder1Yr","type":["null",{"type":"record","name":"IsCallOrPutUnder1Yr","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsFirstLienLoan","type":["null",{"type":"record","name":"IsFirstLienLoan","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsFixedPriceIssue","type":["null",{"type":"record","name":"IsFixedPriceIssue","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsFloatRateIssue","type":["null",{"type":"record","name":"IsFloatRateIssue","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsForeignIssue","type":["null",{"type":"record","name":"IsForeignIssue","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsHighYield","type":["null",{"type":"record","name":"IsHighYield","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsIslamicFinancing","type":["null",{"type":"record","name":"IsIslamicFinancing","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsLoanCvt","type":["null",{"type":"record","name":"IsLoanCvt","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsLoanDocAvail","type":["null",{"type":"record","name":"IsLoanDocAvail","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsMainTranche","type":["null",{"type":"record","name":"IsMainTranche","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsMaturityExtendable","type":["null",{"type":"record","name":"IsMaturityExtendable","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsMaturityExtended","type":["null",{"type":"record","name":"IsMaturityExtended","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsMgrNotAvail","type":["null",{"type":"record","name":"IsMgrNotAvail","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsPricingLinkedToMargin","type":["null",{"type":"record","name":"IsPricingLinkedToMargin","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsPricingUndisclosed","type":["null",{"type":"record","name":"IsPricingUndisclosed","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsRankEligible","type":["null",{"type":"record","name":"IsRankEligible","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsSecondLienLoan","type":["null",{"type":"record","name":"IsSecondLienLoan","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsSeniorDebt","type":["null",{"type":"record","name":"IsSeniorDebt","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsShortTermLoan","type":["null",{"type":"record","name":"IsShortTermLoan","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsStdLtEligible","type":["null",{"type":"record","name":"IsStdLtEligible","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IsTermLoan","type":["null",{"type":"record","name":"IsTermLoan","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]},{"name":"IslamicFinancingTypes","type":["null",{"type":"record","name":"IslamicFinancingTypes","fields":[{"name":"IslamicFinTypeCode","type":["null",{"type":"record","name":"IslamicFinTypeCode","namespace":"auto.generated.IslamicFinancingTypes","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]}]}]},{"name":"IssueDescriptionTexts","type":["null",{"type":"record","name":"IssueDescriptionTexts","fields":[{"name":"IssueText","type":["null",{"type":"array","items":{"type":"record","name":"IssueText","namespace":"auto.generated.IssueDescriptionTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.IssueDescriptionTexts.IssueText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}}]}]}]},{"name":"LboSponsors","type":["null",{"type":"record","name":"LboSponsors","fields":[{"name":"LboSponsor","type":["null",{"type":"array","items":{"type":"record","name":"LboSponsor","namespace":"auto.generated.LboSponsors","fields":[{"name":"LboSponsorImmParentCidgen","type":["null",{"type":"record","name":"LboSponsorImmParentCidgen","namespace":"auto.generated.LboSponsors.LboSponsor","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"LboSponsorEquityPct","type":["null",{"type":"record","name":"LboSponsorEquityPct","namespace":"auto.generated.LboSponsors.LboSponsor","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"LboSponsorRoleCode","type":["null",{"type":"record","name":"LboSponsorRoleCode","namespace":"auto.generated.LboSponsors.LboSponsor","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"LboSponsorCidgen","type":["null",{"type":"record","name":"LboSponsorCidgen","namespace":"auto.generated.LboSponsors.LboSponsor","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"LboSponsorImmParentEntityId","type":["null",{"type":"record","name":"LboSponsorImmParentEntityId","namespace":"auto.generated.LboSponsors.LboSponsor","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.LboSponsors.LboSponsor.LboSponsorImmParentEntityId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"LboSponsorUltParentEntityId","type":["null",{"type":"record","name":"LboSponsorUltParentEntityId","namespace":"auto.generated.LboSponsors.LboSponsor","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.LboSponsors.LboSponsor.LboSponsorUltParentEntityId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"LboSponsorEntityId","type":["null",{"type":"record","name":"LboSponsorEntityId","namespace":"auto.generated.LboSponsors.LboSponsor","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.LboSponsors.LboSponsor.LboSponsorEntityId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"MidParents","type":["null",{"type":"record","name":"MidParents","namespace":"auto.generated.LboSponsors.LboSponsor","fields":[{"name":"MidParent","type":["null",{"type":"array","items":{"type":"record","name":"MidParent","namespace":"auto.generated.LboSponsors.LboSponsor.MidParents","fields":[{"name":"LboSponsorMidParentCidgen","type":["null",{"type":"record","name":"LboSponsorMidParentCidgen","namespace":"auto.generated.LboSponsors.LboSponsor.MidParents.MidParent","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"LboSponsorMidParentEntityId","type":["null",{"type":"record","name":"LboSponsorMidParentEntityId","namespace":"auto.generated.LboSponsors.LboSponsor.MidParents.MidParent","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.LboSponsors.LboSponsor.MidParents.MidParent.LboSponsorMidParentEntityId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]}]}}]}]}]},{"name":"LboSponsorUltParentCidgen","type":["null",{"type":"record","name":"LboSponsorUltParentCidgen","namespace":"auto.generated.LboSponsors.LboSponsor","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]}]}}]}]}]},{"name":"LevRatioMax","type":["null",{"type":"record","name":"LevRatioMax","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"LevRatioMin","type":["null",{"type":"record","name":"LevRatioMin","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"LiquidationStatusCode","type":["null",{"type":"record","name":"LiquidationStatusCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"LoanFees","type":["null",{"type":"record","name":"LoanFees","fields":[{"name":"LoanFee","type":["null",{"type":"array","items":{"type":"record","name":"LoanFee","namespace":"auto.generated.LoanFees","fields":[{"name":"AllFeesText","type":["null",{"type":"record","name":"AllFeesText","namespace":"auto.generated.LoanFees.LoanFee","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.LoanFees.LoanFee.AllFeesText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"AllFeesTextLevel","type":["null",{"type":"record","name":"AllFeesTextLevel","namespace":"auto.generated.LoanFees.LoanFee","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]}]}}]}]}]},{"name":"LoanTypeDescriptionTexts","type":["null",{"type":"record","name":"LoanTypeDescriptionTexts","fields":[{"name":"LoanTypeText","type":["null",{"type":"record","name":"LoanTypeText","namespace":"auto.generated.LoanTypeDescriptionTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.LoanTypeDescriptionTexts.LoanTypeText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"LpcMasterTranchePermId","type":["null",{"type":"record","name":"LpcMasterTranchePermId","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.LpcMasterTranchePermId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"MarginTypeCode1","type":["null",{"type":"record","name":"MarginTypeCode1","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"MarginTypeCode2","type":["null",{"type":"record","name":"MarginTypeCode2","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"MarginTypeCode3","type":["null",{"type":"record","name":"MarginTypeCode3","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"MarketTypeCode","type":["null",{"type":"record","name":"MarketTypeCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"MasterDealType","type":["null",{"type":"record","name":"MasterDealType","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"MaturityDate","type":["null",{"type":"record","name":"MaturityDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"MaturityDescriptionTexts","type":["null",{"type":"record","name":"MaturityDescriptionTexts","fields":[{"name":"MaturityText","type":["null",{"type":"array","items":{"type":"record","name":"MaturityText","namespace":"auto.generated.MaturityDescriptionTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.MaturityDescriptionTexts.MaturityText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}}]}]}]},{"name":"MaxAgentFeeInHostCurr","type":["null",{"type":"record","name":"MaxAgentFeeInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.MaxAgentFeeInHostCurr","fields":[{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxAssignFeeInHostCurr","type":["null",{"type":"record","name":"MaxAssignFeeInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.MaxAssignFeeInHostCurr","fields":[{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxClosingFeeInHostCurr","type":["null",{"type":"record","name":"MaxClosingFeeInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.MaxClosingFeeInHostCurr","fields":[{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxFacilityFeePct","type":["null",{"type":"record","name":"MaxFacilityFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxFrontEndFeePct","type":["null",{"type":"record","name":"MaxFrontEndFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxLCFeePct","type":["null",{"type":"record","name":"MaxLCFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxLateFeePct","type":["null",{"type":"record","name":"MaxLateFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxMgmtFeeInHostCurr","type":["null",{"type":"record","name":"MaxMgmtFeeInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.MaxMgmtFeeInHostCurr","fields":[{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxPrepymtFeePct","type":["null",{"type":"record","name":"MaxPrepymtFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxReductionOrTerminationFeePct","type":["null",{"type":"record","name":"MaxReductionOrTerminationFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxSpreadOverAbr","type":["null",{"type":"record","name":"MaxSpreadOverAbr","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxSpreadOverBankAcceptRate","type":["null",{"type":"record","name":"MaxSpreadOverBankAcceptRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxSpreadOverCDRate","type":["null",{"type":"record","name":"MaxSpreadOverCDRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxSpreadOverCPRate","type":["null",{"type":"record","name":"MaxSpreadOverCPRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxSpreadOverFedFundsRate","type":["null",{"type":"record","name":"MaxSpreadOverFedFundsRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxSpreadOverLibor","type":["null",{"type":"record","name":"MaxSpreadOverLibor","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxSpreadOverPrimeRate","type":["null",{"type":"record","name":"MaxSpreadOverPrimeRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxSpreadOverTBRate","type":["null",{"type":"record","name":"MaxSpreadOverTBRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MaxUtilizationFeePct","type":["null",{"type":"record","name":"MaxUtilizationFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinAgentFeeInHostCurr","type":["null",{"type":"record","name":"MinAgentFeeInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.MinAgentFeeInHostCurr","fields":[{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinAssignFeeInHostCurr","type":["null",{"type":"record","name":"MinAssignFeeInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.MinAssignFeeInHostCurr","fields":[{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinClosingFeeInHostCurr","type":["null",{"type":"record","name":"MinClosingFeeInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.MinClosingFeeInHostCurr","fields":[{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinFacilityFeePct","type":["null",{"type":"record","name":"MinFacilityFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinFrontEndFeePct","type":["null",{"type":"record","name":"MinFrontEndFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinLCFeePct","type":["null",{"type":"record","name":"MinLCFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinLateFeePct","type":["null",{"type":"record","name":"MinLateFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinMgmtFeeInHostCurr","type":["null",{"type":"record","name":"MinMgmtFeeInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.MinMgmtFeeInHostCurr","fields":[{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinPrepymtFeePct","type":["null",{"type":"record","name":"MinPrepymtFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinReductionOrTerminationFeePct","type":["null",{"type":"record","name":"MinReductionOrTerminationFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinSpreadOverAbr","type":["null",{"type":"record","name":"MinSpreadOverAbr","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinSpreadOverBankAcceptRate","type":["null",{"type":"record","name":"MinSpreadOverBankAcceptRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinSpreadOverCDRate","type":["null",{"type":"record","name":"MinSpreadOverCDRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinSpreadOverCPRate","type":["null",{"type":"record","name":"MinSpreadOverCPRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinSpreadOverFedFundsRate","type":["null",{"type":"record","name":"MinSpreadOverFedFundsRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinSpreadOverLibor","type":["null",{"type":"record","name":"MinSpreadOverLibor","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinSpreadOverPrimeRate","type":["null",{"type":"record","name":"MinSpreadOverPrimeRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinSpreadOverTBRate","type":["null",{"type":"record","name":"MinSpreadOverTBRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MinUtilizationFeePct","type":["null",{"type":"record","name":"MinUtilizationFeePct","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"MoodysLoanRatingNumber","type":["null",{"type":"record","name":"MoodysLoanRatingNumber","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"MoodysRatingMax","type":["null",{"type":"record","name":"MoodysRatingMax","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"MoodysRatingMin","type":["null",{"type":"record","name":"MoodysRatingMin","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"MtgAssetBackedIssueTypeCode","type":["null",{"type":"record","name":"MtgAssetBackedIssueTypeCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"NumOfDaysToMaturity","type":["null",{"type":"record","name":"NumOfDaysToMaturity","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"NumOfRepymtPeriod","type":["null",{"type":"record","name":"NumOfRepymtPeriod","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"NumOfYrsToFinalMaturity","type":["null",{"type":"record","name":"NumOfYrsToFinalMaturity","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"NumOfYrsToMaturity","type":["null",{"type":"record","name":"NumOfYrsToMaturity","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"NumOfYrsUntilPut","type":["null",{"type":"record","name":"NumOfYrsUntilPut","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"NumofYrsOfCallProtection","type":["null",{"type":"record","name":"NumofYrsOfCallProtection","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"OfferPricePct","type":["null",{"type":"record","name":"OfferPricePct","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"OrigTrancheAmt","type":["null",{"type":"record","name":"OrigTrancheAmt","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.OrigTrancheAmt","fields":[{"name":"scale","type":["null","long"],"doc":"long"},{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"OrigTrancheAmtInHostCurr","type":["null",{"type":"record","name":"OrigTrancheAmtInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.OrigTrancheAmtInHostCurr","fields":[{"name":"scale","type":["null","long"],"doc":"long"},{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"OrigTrancheCurrencyCode","type":["null",{"type":"record","name":"OrigTrancheCurrencyCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"OrigTrancheCurrencyId","type":["null",{"type":"record","name":"OrigTrancheCurrencyId","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.OrigTrancheCurrencyId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"PerformanceLinkedFeeCode","type":["null",{"type":"record","name":"PerformanceLinkedFeeCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"PerformanceLinkedPricingCode","type":["null",{"type":"record","name":"PerformanceLinkedPricingCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"PricingBaseRates","type":["null",{"type":"record","name":"PricingBaseRates","fields":[{"name":"PricingRateCode","type":["null",{"type":"array","items":{"type":"record","name":"PricingRateCode","namespace":"auto.generated.PricingBaseRates","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}}]}]}]},{"name":"PricingTexts","type":["null",{"type":"record","name":"PricingTexts","fields":[{"name":"PricingText","type":["null",{"type":"array","items":{"type":"record","name":"PricingText","namespace":"auto.generated.PricingTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.PricingTexts.PricingText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}}]}]}]},{"name":"PrinAmtThisMkt","type":["null",{"type":"record","name":"PrinAmtThisMkt","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.PrinAmtThisMkt","fields":[{"name":"scale","type":["null","long"],"doc":"long"},{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"PrinAmtThisMktInHostCurr","type":["null",{"type":"record","name":"PrinAmtThisMktInHostCurr","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.PrinAmtThisMktInHostCurr","fields":[{"name":"scale","type":["null","long"],"doc":"long"},{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"PutDate","type":["null",{"type":"record","name":"PutDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"PutFreqCode","type":["null",{"type":"record","name":"PutFreqCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"PutTypeCode","type":["null",{"type":"record","name":"PutTypeCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"RelatedDeals","type":["null",{"type":"record","name":"RelatedDeals","fields":[{"name":"RelatedDeal","type":["null",{"type":"array","items":{"type":"record","name":"RelatedDeal","namespace":"auto.generated.RelatedDeals","fields":[{"name":"RelatedSdcDealTypeCode","type":["null",{"type":"record","name":"RelatedSdcDealTypeCode","namespace":"auto.generated.RelatedDeals.RelatedDeal","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"RelatedSdcDealNumber","type":["null",{"type":"record","name":"RelatedSdcDealNumber","namespace":"auto.generated.RelatedDeals.RelatedDeal","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"RelatedDealId","type":["null",{"type":"record","name":"RelatedDealId","namespace":"auto.generated.RelatedDeals.RelatedDeal","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.RelatedDeals.RelatedDeal.RelatedDealId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]}]}}]}]}]},{"name":"RepaymentSchedules","type":["null",{"type":"record","name":"RepaymentSchedules","fields":[{"name":"RepaymentSchedule","type":["null",{"type":"array","items":{"type":"record","name":"RepaymentSchedule","namespace":"auto.generated.RepaymentSchedules","fields":[{"name":"RepymtPct","type":["null",{"type":"record","name":"RepymtPct","namespace":"auto.generated.RepaymentSchedules.RepaymentSchedule","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"RepymtAmt","type":["null",{"type":"record","name":"RepymtAmt","namespace":"auto.generated.RepaymentSchedules.RepaymentSchedule","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.RepaymentSchedules.RepaymentSchedule.RepymtAmt","fields":[{"name":"scale","type":["null","long"],"doc":"long"},{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"RepymtDate","type":["null",{"type":"record","name":"RepymtDate","namespace":"auto.generated.RepaymentSchedules.RepaymentSchedule","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]}]}}]}]}]},{"name":"RepaymentTexts","type":["null",{"type":"record","name":"RepaymentTexts","fields":[{"name":"RepymtText","type":["null",{"type":"record","name":"RepymtText","namespace":"auto.generated.RepaymentTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.RepaymentTexts.RepymtText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}]}]}]},{"name":"RepymtEndDate","type":["null",{"type":"record","name":"RepymtEndDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"RepymtFreqCode","type":["null",{"type":"record","name":"RepymtFreqCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"RepymtStartDate","type":["null",{"type":"record","name":"RepymtStartDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"RepymtTypeCode","type":["null",{"type":"record","name":"RepymtTypeCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"SPLoanRatingNumber","type":["null",{"type":"record","name":"SPLoanRatingNumber","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"SPRatingMax","type":["null",{"type":"record","name":"SPRatingMax","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"SPRatingMin","type":["null",{"type":"record","name":"SPRatingMin","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"Subfacilities","type":["null",{"type":"record","name":"Subfacilities","fields":[{"name":"SubFacility","type":["null",{"type":"array","items":{"type":"record","name":"SubFacility","namespace":"auto.generated.Subfacilities","fields":[{"name":"SubFacilityTypeCode","type":["null",{"type":"record","name":"SubFacilityTypeCode","namespace":"auto.generated.Subfacilities.SubFacility","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"SubFacilityAmtInHostCurr","type":["null",{"type":"record","name":"SubFacilityAmtInHostCurr","namespace":"auto.generated.Subfacilities.SubFacility","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.Subfacilities.SubFacility.SubFacilityAmtInHostCurr","fields":[{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"SubFacilityAmt","type":["null",{"type":"record","name":"SubFacilityAmt","namespace":"auto.generated.Subfacilities.SubFacility","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.Subfacilities.SubFacility.SubFacilityAmt","fields":[{"name":"currencyId","type":["null","long"],"doc":"long"},{"name":"sdcCurrencyCode","type":["null","string"],"doc":"string"}]}]},{"name":"v","type":["null","double"],"doc":"double"}]}]}]}}]}]}]},{"name":"SyndicateTypeCode","type":["null",{"type":"record","name":"SyndicateTypeCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"TargetMktNationCode","type":["null",{"type":"record","name":"TargetMktNationCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]},{"name":"TargetMktNationId","type":["null",{"type":"record","name":"TargetMktNationId","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.TargetMktNationId","fields":[{"name":"objectTypeId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"TrancheClosingDate","type":["null",{"type":"record","name":"TrancheClosingDate","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"TrancheFinancialCloseDate","type":["null",{"type":"record","name":"TrancheFinancialCloseDate","fields":[{"name":"v","type":["null","long"],"doc":"date"}]}]},{"name":"TrancheNum","type":["null",{"type":"record","name":"TrancheNum","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"TrancheTypeCode","type":["null",{"type":"record","name":"TrancheTypeCode","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"UsdExchangeRate","type":["null",{"type":"record","name":"UsdExchangeRate","fields":[{"name":"v","type":["null","double"],"doc":"double"}]}]},{"name":"UseOfProceeds","type":["null",{"type":"record","name":"UseOfProceeds","fields":[{"name":"UseOfProceed","type":["null",{"type":"array","items":{"type":"record","name":"UseOfProceed","namespace":"auto.generated.UseOfProceeds","fields":[{"name":"UopCode","type":["null",{"type":"record","name":"UopCode","namespace":"auto.generated.UseOfProceeds.UseOfProceed","fields":[{"name":"v","type":["null","long"],"doc":"long"}]}]},{"name":"IsPrimUopCode","type":["null",{"type":"record","name":"IsPrimUopCode","namespace":"auto.generated.UseOfProceeds.UseOfProceed","fields":[{"name":"v","type":["null","boolean"],"doc":"boolean"}]}]}]}}]}]}]},{"name":"UseOfProceedsTexts","type":["null",{"type":"record","name":"UseOfProceedsTexts","fields":[{"name":"UopText","type":["null",{"type":"array","items":{"type":"record","name":"UopText","namespace":"auto.generated.UseOfProceedsTexts","fields":[{"name":"a","type":["null",{"type":"record","name":"a","namespace":"auto.generated.UseOfProceedsTexts.UopText","fields":[{"name":"sdcLanguageCode","type":["null","long"],"doc":"long"},{"name":"languageId","type":["null","long"],"doc":"long"}]}]},{"name":"v","type":["null","string"],"doc":"string"}]}}]}]}]},{"name":"YieldTypeCode","type":["null",{"type":"record","name":"YieldTypeCode","fields":[{"name":"v","type":["null","string"],"doc":"string"}]}]}]}"""
  val schema = new Schema.Parser().parse(schemastr)
  private def processMsg(avroMsg: AvroMessage.Message): Unit= {
    val newMsg = avroMsg.newVal
    val msgType = avroMsg.getMsgType
    val dDomain = avroMsg.dataDomain
    val dType = avroMsg.dataType
    val msgKey = avroMsg.key
    val oldMsg = avroMsg.oldVal

    System.out.println(s"Incoming Message: msgType=$msgType, dataDomain=$dDomain, dataType=$dType, msgKey=$msgKey")
    msgType match {
      case MsgOperation.Insert | MsgOperation.Modify => {

        val jsonStr = AvroUtil.decode(schema, newMsg.get.toArray).toString
        //val json = JacksonUtil.parseObject(jsonStr)
        //RecordUtil.appendPKAndTags(rType, json)
        //val record = KeyHierarchyUtil.extractKeyHierarchy(json)
        //(dDomain, dType, msgKey, record)
        System.out.println(s"new value is $jsonStr")
      }
      case MsgOperation.Delete => {
        //(dDomain, dType, msgKey, null)
      }
      case MsgOperation.Empty => {
        System.out.println("Empty action, nothing to do")
        //("", "", "", null)
      }
    }
  }


}


object KafkaUtilV2 {
    val brokers = "c223gspzbmq01.int.thomsonreuters.com:9092,c935vnwzbmq02.int.thomsonreuters.com:9092,c064bzxzbmq03.int.thomsonreuters.com:9092,c546wpyzbmq04.int.thomsonreuters.com:9092,c242gxtzbmq05.int.thomsonreuters.com:9092,c971ytdzbmq06.int.thomsonreuters.com:9092"
    val topics = "ecpcisqeddscat.data.v2.index.CL3Instrument_search,ecpcisqeddscat.data.v2.index.OA_search,ecpcisqeddscat.data.v2.index.MIFID2_search,ecpcisqeddscat.data.v2.index.CL3Quote_search,ecpcisqeddscat.data.v2.index.INSTRUMENTKEYMASTER_search"

    val cdfbrokersproxy="kafka-cisdevhdc.int.thomsonreuters.com:9092"
    val cdfbrokers="c094npx.int.thomsonreuters.com:9092,c178xyn.int.thomsonreuters.com:9092,c713rqv.int.thomsonreuters.com:9092,c715wzg.int.thomsonreuters.com:9092,c820jrp.int.thomsnreuters.com:9092"
    val cdfTopics="ecprepcicdf.MiFIDInstrument.All.1.Default"
    var adminClient :AdminClient = null
    val kafkaService: KafkaService =  new KafkaFactory().create()
    lazy val logger: Logger = LoggerFactory.getLogger(getClass)

    def getAdminClient():AdminClient = {
        val adminClientProperties = new Properties()
        adminClientProperties.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, KafkaUtilV2.brokers)
        if(adminClient != null)
            return adminClient
        adminClient = AdminClient.create(adminClientProperties)
        adminClient
    }

    def printHelp(): Unit = {
        println(
            """
              |kafkautil tool with Kafka client 0.9.0.1. Usage:
              |kafkautil --action <action> --zookeeper <zookeeper> --brokers <brokers> --topics <topics>
              |
              |Options:
              |
              |--action <action>          [Required] Run a specific action, available actions are:
              |                           purge - Purge kafka message queue by setting retention.ms=0
              |                                   After message got purged, remove this setting
              |                           get-size - Return the log size of all partitions of a topic
              |                           get-offset - Print partition and offset info for a consumer
              |                           set-offset - Set partition and offset for a consumer
              |                           check - Check topics existence
              |
              |--zookeeper <zookeeper>    [Required] Zookeeper connection string for Kafka brokers
              |
              |--brokers <brokers>        [Required] Kafka brokers, for example: 10.0.0.1:9092,10.0.0.2:9092
              |
              |--topics <topics>          [Required] Kafka topic
              |
              |--consumer-group <groupId> [Optional] Used with actions: get-offset and set-offset
              |
              |--offsets <offsets>        [Optional] Used with action set-offset, the format is:
              |                           pid=offset[,pid=offset]. For example: 0=0,1=1000,2=0
              |
              |
              |Examples:
              |
              |1. Purge message in topic test
              |kafkautil --action purge --zookeeper localhost:2181/kafka --brokers localhost:9092 --topics test
              |
              |2. Get log size of topic test
              |kafkautil --action get-size --zookeeper localhost:2181/kafka --brokers localhost:9092 --topics test
              |
              |3. Get offset of consumer consumer-cat and topic test
              |kafkautil --action get-offset --zookeeper localhost:2181/kafka --brokers localhost:9092 \
              |--topics test --consumer-group consumer-cat
              |
              |4. Set offset of consumer consumer-cat and topic test, set partition 2 to 1000
              |kafkautil --action set-offset --zookeeper localhost:2181/kafka --brokers localhost:9092 \
              |--topics test --consumer-group consumer-cat --offsets 2=1000
              |
              |5. Set offset of consumer consumer-cat and topic test, set partition 1 to 5000 and other partitions to 0
              |kafkautil --action set-offset --zookeeper localhost:2181/kafka --brokers localhost:9092 \
              |--topics test --consumer-group consumer-cat --offsets 0=0,1=5000,2=0
              |
              |6. Topics existence check for topic test1 and test2
              |kafkautil --action check --zookeeper localhost:2181/kafka --brokers localhost:9092 --topics test1,test2
              |
      """.stripMargin)
    }


    def main(args: Array[String]): Unit = {
        // Disable log4j output
        val prop = new Properties()
        prop.put("log4j.rootLogger", "OFF")
        prop.put("log4j.logger.com.tr.rts.utility.kafka.message", "INFO,console")
        prop.put("log4j.appender.console", "org.apache.log4j.ConsoleAppender")
        prop.put("log4j.appender.console", "org.apache.log4j.ConsoleAppender")
        prop.put("log4j.appender.console.layout", "org.apache.log4j.PatternLayout")
        prop.put("log4j.appender.console.layout.ConversionPattern", "[%p][%d{yyyy-MM-dd HH:mm:ss,SSS}][%c]%m%n")

        PropertyConfigurator.configure(prop)

        val kuv2 = new KafkaUtilV2()

        val (lastbeginOffsets, lastendOffsets) = kuv2.getTopicOffset(KafkaUtilV2.cdfTopics,"",KafkaUtilV2.cdfbrokers)


        while (true){
            Thread.sleep(1000*60)
            val (currentBeginOffsets, currentEndOffsets) = kuv2.getTopicOffset(KafkaUtilV2.cdfTopics,"",KafkaUtilV2.cdfbrokers)
            currentEndOffsets.forEach((topic,offset) =>
            {
                val lastOffset = lastbeginOffsets.get(topic)
                System.out.println(s"rate for topic ${topic.toString} is ${offset - lastOffset}")
            })
        }
//        val consumerGroupId = "mifid_instrument_0.0.21"
//        var last = kuv2.getConsumerLag2("mifid_instrument_0.0.21")
//        while (true) {
//            Thread.sleep(1000 * 60 * 4)
//            val current =  kuv2.getConsumerLag2("mifid_instrument_0.0.21")
//
//            current.foreach(e =>{
//                val currentLag = e._2._2 - e._2._3
//                System.out.println( s"consumter: ${consumerGroupId}, topic:${e._1.topic()}, partition: ${e._1.partition()} , lag: ${currentLag}" )
//
//                val lastTopicConsumer    = last.get(e._1)
//                if(!lastTopicConsumer.isEmpty){
//                    val lastLag = lastTopicConsumer.get._2 -  lastTopicConsumer.get._3
//                    if(currentLag > lastLag){
//                        System.out.println(s"lag is increasing from ${lastLag} to ${currentLag}: ${currentLag - lastLag}")
//                    }
//                }
//
//                if(e._2._3 < e._2._1){
//                    System.out.println(s" out of range now.")
//                }
//
//
//            })
//            last = current
//        }

        //kuv2.getTopicOffset(KafkaUtilV2.topics,"mifid_instrument_0.0.21")

        //ret = kuv2.getBrokers
//        if (args.length < 4) {
//            printHelp()
//            System.exit(-1)
//        }
//        val opts           = CommandLine.parseArgs(args)
//        val action         = opts("action")
//        val zookeeper      = opts("zookeeper")
//        val topics         = opts("topics")
//        val brokers        = opts("brokers")
//        val timeout: Int   = opts.getOrElse("timeout", "0").toInt
//        val consumer_group = opts.getOrElse("consumer-group", "")
//
//        action.toLowerCase match {
//            case "purge" =>
//
//            case "check" =>
//
//            case "get-size" =>
//
//            case "populate-offsets" =>
//              case "get-offset" =>
//
//            case "set-offset" =>
//
//            case "set-conf" =>
//
//            case "get-conf" =>
//
//            case _ =>
//                logger.error(s"Action $action is not supported")
//                System.exit(-1)
//        }
    }
}